Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		Super.OnCreate()
				
		'DISPLAY.SetVirtualSize(480,320)
		
		DEBUG = False
		
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		Return 0
	End
	
End


Class TTmpScreen Extends TScreen

	Field tilemap:TTiled_Map
	Field off_x:Float = 0
	Field off_y:Float = 0
	
	Field layer_map_id_0:Int
	Field layer_map_id_1:Int
	Field layer_map_id_2:Int
	Field layer_map_id_3:Int
	Field layer_map_id_4:Int

	Field layer_col_id:Int
	
	' START when app is created
	Method Start:Void()
		Self.tilemap = New TTiled_Map()
		Self.tilemap.Load("agfx_platform_test.xml")
		
		#Rem
		Self.p2d.AddRenderLayersOrder("TileLayer_parallax")
		Self.p2d.AddRenderLayersOrder("TileLayer_bkg")
		Self.p2d.AddRenderLayersOrder("TileLayer_middle")
		Self.p2d.AddRenderLayersOrder("Objects_Physics")
		Self.p2d.AddRenderLayersOrder("TileLayer_front")
		Self.p2d.AddRenderLayersOrder("TileLayer_hud")
		#End

		Self.layer_map_id_0 = Self.tilemap.GetLayerIDbyName("TileLayer_parallax")
		Self.layer_map_id_1 = Self.tilemap.GetLayerIDbyName("TileLayer_bkg")
		Self.layer_map_id_2 = Self.tilemap.GetLayerIDbyName("TileLayer_middle")
		Self.layer_map_id_3 = Self.tilemap.GetLayerIDbyName("TileLayer_front")
		Self.layer_map_id_4 = Self.tilemap.GetLayerIDbyName("TileLayer_hud")

		Self.layer_col_id = Self.tilemap.GetLayerIDbyName("TileLayer_collision")
		
		Print("TILESETS:")
		Local array_tilesets:Object[] = Self.tilemap.tilesets.ToArray()
		Local array_tilesets_count:Int = array_tilesets.Length()
		
		
		Print(TTiled_Tileset(array_tilesets[0]).name)
		Print(TTiled_Tileset(array_tilesets[1]).name)
		Print(TTiled_Tileset(array_tilesets[2]).name)
		
		Print("LAYERS:")
		Local array_layers:Object[] = Self.tilemap.layers.ToArray()
		Local array_layers_count:Int = array_layers.Length()
		
		Print(TTiled_Layer(array_layers[0]).name)
		Print(tilemap.layers.Get(0).name)
		Print(TTiled_Layer(array_layers[1]).name)
		Print(tilemap.layers.Get(1).name)
		
		

		Local id:Int = Self.tilemap.GetObjectGroupIDbyName("Objects_Physics")

		
'		Print(Self.tilemap.object_groups.Get(id).Find("Player").x)
'		Print(Self.tilemap.object_groups.Get(id).Find("Player").y)

'		Print(Self.tilemap.object_groups.Get(id).Find("Player").properties.Find("shape_type"))


		Self.tilemap.layers.Get(layer_map_id_0).parallax_scale_x = 0.25
		Self.tilemap.layers.Get(layer_map_id_0).parallax_scale_y = 0.25
		Self.tilemap.layers.Get(layer_map_id_0).scale_x = 2.0
		Self.tilemap.layers.Get(layer_map_id_0).scale_y = 2.0

	End
	
	' main app logic loop update
	Method Update:Void()
	
		If KeyDown(KEY_LEFT) off_x = off_x - 2
		If KeyDown(KEY_RIGHT) off_x = off_x + 2
		If KeyDown(KEY_UP) off_y = off_y - 2
		If KeyDown(KEY_DOWN) off_y = off_y + 2
		
		Self.tilemap.SetPosition(off_x,off_y)
	End
	
	' main app render loop
	Method Render:Void()
		Cls
		Self.tilemap.DrawLayer(Self.layer_map_id_0)
		Self.tilemap.DrawLayer(Self.layer_map_id_1)
		Self.tilemap.DrawLayer(Self.layer_map_id_2)
		Self.tilemap.DrawLayer(Self.layer_map_id_3)
		Self.tilemap.DrawLayer(Self.layer_map_id_4)
		Self.tilemap.DrawLayer(Self.layer_col_id)
		Self.tilemap.DrawObjectGroup(0)
		
		'Error ""
	End
End
